﻿<?xml version="1.0"  encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <TasksPath>..\BuildTasks\</TasksPath>
    <CustomAfterWixTargets>$(MSBuildProjectDirectory)\WixFolderInclude.targets</CustomAfterWixTargets>
    <BuildDependsOn>
      PackageFiles;
      $(BuildDependsOn)
    </BuildDependsOn>
  </PropertyGroup>
  
  <Import Project="$(TasksPath)Microsoft.Sdc.Common.tasks" />

  <ItemGroup>
    <Templates Include="Templates\**" />
    <WixFolderInclude Include="TemplatesFolder">
      <SourceFiles>@(Templates)</SourceFiles>
      <RootPath>Templates</RootPath>
      <ParentDirectoryRef>Templates</ParentDirectoryRef>
    </WixFolderInclude>
  </ItemGroup>

  <Target Name="PackageFiles">
    
    <!-- Recreate output directory -->
    <RemoveDir Directories="$(OutputPath)" />
    <MakeDir Directories="$(OutputPath)" Condition="!Exists($(OutputPath))" />

    <!-- Copy samples files to output directory-->
    <ItemGroup>
      <CopySamples Include="..\Samples\**\*.*" Exclude="..\Samples\**\*.*scc;..\Samples\**\*.sln"/>
    </ItemGroup>
    <Copy SourceFiles="@(CopySamples)" DestinationFolder="$(OutputPath)Samples\%(RecursiveDir)" />
    
    <!-- Remove development time bindings from sample projects -->
    <ItemGroup>
      <XmlNamespace Include="MSBuildNamespace">
        <Prefix>msb</Prefix>
        <Uri>http://schemas.microsoft.com/developer/msbuild/2003</Uri>
      </XmlNamespace>
    </ItemGroup>

    <Xml.XslTransform
                XmlFile="$(OutputPath)Samples\CSharp\AdventureWorks\AdventureWorks.csproj"
                XslFile="ReplaceReferences.xsl"
                ResultFile="$(OutputPath)Samples\CSharp\AdventureWorks\AdventureWorks.csproj.temp" />

    <Copy SourceFiles="$(OutputPath)Samples\CSharp\AdventureWorks\AdventureWorks.csproj.temp" DestinationFiles="$(OutputPath)Samples\CSharp\AdventureWorks\AdventureWorks.csproj" />    
    <Delete Files="$(OutputPath)Samples\CSharp\AdventureWorks\AdventureWorks.csproj.temp" />

    <Xml.XslTransform
                XmlFile="$(OutputPath)Samples\VisualBasic\AdventureWorks\AdventureWorks.vbproj"
                XslFile="ReplaceReferences.xsl"
                ResultFile="$(OutputPath)Samples\VisualBasic\AdventureWorks\AdventureWorks.vbproj.temp" />

    <Copy SourceFiles="$(OutputPath)Samples\VisualBasic\AdventureWorks\AdventureWorks.vbproj.temp" DestinationFiles="$(OutputPath)Samples\VisualBasic\AdventureWorks\AdventureWorks.vbproj" />
    <Delete Files="$(OutputPath)Samples\VisualBasic\AdventureWorks\AdventureWorks.vbproj.temp" />

    <!-- Add samples to WIX Fragment-->
    <ItemGroup>
      <Samples Include="$(OutputPath)Samples\**" />
      <WixFolderInclude Include="SamplesFolder">
        <SourceFiles>@(Samples)</SourceFiles>
        <RootPath>$(OutputPath)Samples</RootPath>
        <ParentDirectoryRef>Samples</ParentDirectoryRef>
      </WixFolderInclude>
    </ItemGroup>

    <!-- Zip filter VSTempaltes-->
    <Delete Files="$(OutputPath)DynamicDataWebApplicationFilter.cs.zip" />
    <Zip.Create PathToZipFile="$(OutputPath)DynamicDataWebApplicationFilter.cs.zip" />
    <Zip.AddFile PathToFile="ItemTemplates\CSharp" RootFolder="ItemTemplates\CSharp" PathToZipFile="$(OutputPath)DynamicDataWebApplicationFilter.cs.zip" />

    <Delete Files="$(OutputPath)DynamicDataWebApplicationFilter.vb.zip" />
    <Zip.Create PathToZipFile="$(OutputPath)DynamicDataWebApplicationFilter.vb.zip" />
    <Zip.AddFile PathToFile="ItemTemplates\VisualBasic" RootFolder="ItemTemplates\VisualBasic" PathToZipFile="$(OutputPath)DynamicDataWebApplicationFilter.vb.zip" />

  </Target>
  
</Project>